package com.hmall.item.search.web;

import com.hmall.common.dto.PageDTO;
import com.hmall.common.pojo.ItemDoc;
import com.hmall.item.search.pojo.PageResult;
import com.hmall.item.search.pojo.RequestParams;
import com.hmall.item.search.service.SearchService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @author 29143
 */
@RestController
@RequestMapping("/search")
public class SearchWeb {

    @Autowired
    private SearchService searchService;

    /**
     * 自动补全功能
     * @param key
     * @return
     */
    @GetMapping("/suggestion")
    public List<String> getSuggestion(String key){
        return searchService.getSuggestion(key);
    }

    /**
     * 过滤项聚合功能
     * @param params
     * @return
     */
    @PostMapping("/filters")
    public Map<String,List<String>> getFilters(@RequestBody RequestParams params){
        return searchService.getFilters(params);
    }

    @PostMapping("/list")
    public PageDTO<ItemDoc> getList(@RequestBody RequestParams params){
        return searchService.getList(params);
    }

}
